function ret = prand3(size, randstream)
%PRAND3
%  RET = PRAND3(SIZE, RANDSTREAM) generates a transform and detransform 
%  from a RandStream. SIZE is the number of elements, and randstream is any
%  RandStream. You can generate one from getRandStream using a seed, or
%  leave it blank, it will use the global RandStream as default.
  if nargin < 2
      randstream = RandStream.getGlobalStream()
  end
  r = randstream.randperm(size);
  u = r;
  for i=1:size
    u(1,r(1,i))=i;
  end
  ret = [r;u];
end
